<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>layui</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
		<link rel="stylesheet" href="__PUBLIC__/layui/css/layui.css" media="all">
		<link rel="stylesheet" href="__PUBLIC__/font-awesome/css/font-awesome.min.css" media="all" />
		<link rel="stylesheet" href="__CSS__/admin.css" media="all">
	</head>
    <style>
    	.layui-word-aux{
    		color: #2BB6F6!important;
    	}
	    .layui-form-label {
		    width: 140px;
		}
		.yanshi {
			height: 38px; 
		    line-height: 38px;
		    border: 1px solid #e6e6e6;
		    background-color: #fff;
		    border-radius: 2px;
		    width: 185px;
	    }
    </style>
	<body style="padding:10px;">
		<div class="tplay-body-div">
			<div class="layui-tab">
				<ul class="layui-tab-title">
				    <li><a href="{:url('admin/member/level')}" class="a_menu">会员等级列表</a></li>
					<li class="layui-this">新增会员等级</li>
				</ul>
			</div>
			<form class="layui-form" id="add" name="myForm"> 
				<div class="layui-form-item">
					<label class="layui-form-label">等级名称</label>
					<div class="layui-input-inline">
						<input name="name" id="name" lay-verify="required" placeholder="请输入等级名称" autocomplete="off" class="layui-input" type="text" maxlength="20">
					</div>
					<div class="layui-form-mid" style="color: #999;">限定20个字符</div>
				</div>

				<div class="layui-form-item">
					<label class="layui-form-label">充值金额</label>
					<div class="layui-input-inline">
						<input name="price" id="price" lay-verify="required" placeholder="请输入充值金额" autocomplete="off" class="layui-input" type="number">
					</div>
				</div> 
				
				<div class="layui-form-item">
					<label class="layui-form-label">活动时期</label>
					<div class="layui-input-block">
						<input type="radio" name="date" value="0" title="永久">
						<input type="radio" name="date" value="1" title="限时">
					</div>
				</div>
				
				
				<div class="layui-card-header">即时赠送</div>
				<div class="layui-form-item">
					<label class="layui-form-label">赠送年限</label>
					<div class="layui-input-inline">
						<input name="zs_date1" value="1" placeholder="1" class="layui-input" type="text" readonly>
					</div> 
				</div> 
               <div class="layui-form-item jz">
               	    <div class="layui-form-item">
					<label class="layui-form-label">房型</label>
					<div class="layui-input-inline">
						<select name="house_id1[]" id="hou1" lay-filter="aihao" lay-ignore class="yanshi">  
							<option value="">请选择房型</option> 
							{volist name="$house" id="vo"}
							<option value="{$vo.id}">{$vo.room_name}</option> 
							{/volist}
						</select>
					</div>
					<div class="layui-input-inline">
						<input name="zs_num1[]" id="zs_num1" placeholder="请输入房间数" autocomplete="off" class="layui-input" type="text">
					</div> 
					<input type="hidden" name="id1[]"/>
					<i onclick="jis(0)" class="layui-icon layui-icon-add-circle" style="cursor:pointer;position: relative;top: 9px;font-size: 20px;color: rgba(43, 182, 246, 1);">&#xe61f;</i>
				    </div>
               </div>
				
				<div class="layui-card-header">后续赠送</div>
				<div class="layui-form-item">
					<label class="layui-form-label">赠送年限</label>
					<div class="layui-input-inline">
						<input name="zs_date" id="zs_date" placeholder="请输入赠送年限" autocomplete="off" class="layui-input" type="text">
					</div> 
				</div>
               <div class="layui-form-item hx">
               <div class="layui-form-item">
					<label class="layui-form-label">房型</label>
					<div class="layui-input-inline">
						<select name="house_id[]" id="hou" lay-filter="aihao" lay-ignore class="yanshi">  
							<option value="">请选择房型</option> 
							{volist name="$house" id="vo"}
							<option value="{$vo.id}">{$vo.room_name}</option> 
							{/volist}
						</select>
					</div>
					<div class="layui-input-inline">
						<input name="zs_num[]" id="zs_num" placeholder="请输入房间数" autocomplete="off" class="layui-input" type="text">
					</div> 
					<input type="hidden" name="id2[]"/>
					<i onclick="jis(1)" class="layui-icon layui-icon-add-circle" style="cursor:pointer;position: relative;top: 9px;font-size: 20px;color: rgba(43, 182, 246, 1);">&#xe61f;</i>
				</div> 
				</div> 
				<div class="layui-form-item">
					<div class="layui-input-block">
						<button class="layui-btn" lay-submit lay-filter="btn">立即提交</button>
						<button type="reset" class="layui-btn layui-btn-primary">重置</button>
					</div>
				</div> 
			</form>

			<script src="__PUBLIC__/layui/layui.js"></script>
			<script src="__PUBLIC__/jquery/jquery.min.js"></script> 
			<script>
				layui.use(['layer', 'form'], function() {
					var layer = layui.layer,
					$ = layui.jquery,
					form = layui.form;
					$(window).on('load', function() {
						form.on('submit(btn)', function(data) { 
							var x = document.forms["myForm"]["name"].value; 
							if (x == null || x == "") {
							 	layer.msg("请填写所有信息"); 
							 	return false;
							}
							var da = $('input:radio:checked').val();
							if(!da){
								layer.msg("请选择活动时期"); 
							 	return false;
							}
							
							var hou1 = $('#hou1').val();
							var zs_num1 = $('#zs_num1').val();
							
							var hou = $('#hou').val();
							var zs_num = $('#zs_num').val();
							var zs_date = $('#zs_date1').val();
							if(!hou1 && !zs_num1 && !hou && !zs_num && !zs_date){
								layer.msg("请选择一种赠送方式"); 
								return false;
							}
							
							if(zs_num1){
								if(!hou1){
									layer.msg("请选择即时赠送房型"); 
								 	return false;
								}
							} 
							
							if(zs_num || zs_date){
								if(!hou){
									layer.msg("请选择后续赠送房型"); 
								 	return false;
								}
							}
							
							$.ajax({
								url: "{:url('admin/member/leveladd')}",
								data: $('#add').serialize(),
								type: 'post',
								async: false,
								success: function(res) { 
								    if(res.code == 1) {
			                              layer.msg(res.msg, function(index){
			                                location.href = res.url;
			                              })
			                        } else {
			                              layer.msg(res.msg);
			                        }
								}
							})
							return false;
						});
					});
				});
				
				function clearNoNum(obj) {
				    obj.value = obj.value.replace(/[^\d.]/g, ""); //清除"数字"和"."以外的字符  
				    obj.value = obj.value.replace(/^\./g, ""); //验证第一个字符是数字而不是  
				    obj.value = obj.value.replace(/\.{2,}/g, "."); //只保留第一个. 清除多余的  
				    obj.value = obj.value.replace(".", "$#$").replace(/\./g, "").replace("$#$", ".");
				    obj.value = obj.value.replace(/^(\-)*(\d+)\.(\d{1}).*$/, '$1$2.$3'); //只能输入6个小数  
				}
				
				function jis(type){ 
                    $.ajax({
						url: "/admin/member/levellist?type="+type, 
						type: 'get',
						dataType: 'html', 
						success: function(res) {  
							console.log(res);
						    if(res) {
						    	if(type == 1){
						    		$('.hx').append(res);
						    	}else{
						    		$('.jz').append(res);
						    	}
	                        } else {
	                            if(type == 1){
						    		$('.hx').append('');
						    	}else{
						    		$('.jz').append('');
						    	}
	                        }
						}
					})
				}
			</script>
		</div>
	</body>

</html>